import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:${USER}
 * Date:${YEAR}-${MONTH}-${DAY}
 * ${TIME}
 */
public class Main {
    public int calculate(String _s) {
        Stack<Integer> stack=new Stack<>();
        char op='+';
        int i=0,n=_s.length();
        char[] s=_s.toCharArray();
        while (i<n){
            if(s[i]==' ')i++;
            else if(s[i]>='0'&&s[i]<='9'){
                int tmp=0;
                while (i<n&&s[i]>='0'&&s[i]<='9'){
                    tmp=tmp*10+(s[i]-'0');
                    i++;
                }
                if(op=='+')stack.push(tmp);
                else if(op=='-')stack.push(-tmp);
                else if(op=='*')stack.push(stack.pop()*tmp);
                else if(op=='/')stack.push(stack.pop()/tmp);
            }
            else {
                op=s[i];
                i++;
            }
        }
        int ret=0;
        while (!stack.isEmpty()){
            ret+=stack.pop();
        }
        return ret;
    }
}